/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <iostream>

using namespace std;

int power(int a,int b,int p)
{
    //declare and initialize the answer
    int ans=1%p;
    for (;b ;b>>=1 )
    {
        if (b&1)//get and judge the lowest level of the binary number b
        {
            ans=(long long)ans*a%p;
        }
        a=(long long)a*a%p;
    }
    return ans;
}
int main_2()
{
//    freopen("/home/csp/Desktop/tedukuri/配套光盘/例题/0x00 基本算法/0x01 位运算/a^b/ab5.in","r",stdin);
//    freopen("/home/csp/Desktop/tedukuri/配套光盘/例题/0x00 基本算法/0x01 位运算/a^b/ab5.out","w",stdout);
    int a,b,p;
    cin>>a>>b>>p;
    cout << power(a,b,p) << endl;
	return 0;
}
